/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BookViewPanel.java
 *
 * Created on 1-gen-2014, 17.43.31
 */

package APP3.bookshop.gui;

import APP3.bookshop.main.BookShop;
import APP3.bookshop.person.author.Author;

/**
 *
 * @author finalfire
 */
public class AuthorViewPanel extends javax.swing.JPanel {

    
    private BookShop bookshop;
    /** Creates new form BookViewPanel */
    public AuthorViewPanel(BookShop b) {
        this.bookshop=b;
        initComponents();
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ViewAuthor_AuthorList = new javax.swing.JList();
        ViewAuthor_AuthorNameLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ViewAuthor_booksByAuthorList = new javax.swing.JList();
        ViewAuthor_DeleteAuthorButton = new javax.swing.JButton();

        jLabel5.setText("jLabel5");

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        jLabel1.setText("View author");

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(51, 51, 51));
        jLabel2.setText("Select an author to view related information");

        ViewAuthor_AuthorList.setModel(bookshop.getAuthorservice().populateAuthorList());
        ViewAuthor_AuthorList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ViewAuthor_AuthorListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(ViewAuthor_AuthorList);

        ViewAuthor_AuthorNameLabel.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        ViewAuthor_AuthorNameLabel.setText("AUTHOR NAME");

        jLabel8.setForeground(new java.awt.Color(51, 51, 51));
        jLabel8.setText("Books written by");

        jScrollPane2.setViewportView(ViewAuthor_booksByAuthorList);

        ViewAuthor_DeleteAuthorButton.setText("Delete author");
        ViewAuthor_DeleteAuthorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ViewAuthor_DeleteAuthorButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 40, Short.MAX_VALUE)
                        .add(jLabel2))
                    .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                    .add(ViewAuthor_AuthorNameLabel)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                    .add(jLabel8)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, ViewAuthor_DeleteAuthorButton))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(ViewAuthor_AuthorNameLabel)
                .add(18, 18, 18)
                .add(jLabel8)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(ViewAuthor_DeleteAuthorButton)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void ViewAuthor_AuthorListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ViewAuthor_AuthorListMouseClicked
        Author a = (Author) ViewAuthor_AuthorList.getSelectedValue();
        ViewAuthor_booksByAuthorList.setModel(bookshop.getAuthorservice().populateAuthorsBooksList(a));
    }//GEN-LAST:event_ViewAuthor_AuthorListMouseClicked

    private void ViewAuthor_DeleteAuthorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ViewAuthor_DeleteAuthorButtonActionPerformed
        Author a = (Author) ViewAuthor_AuthorList.getSelectedValue();
        bookshop.getAuthorservice().removeAuthor(a);
        ViewAuthor_AuthorList.setModel(bookshop.getAuthorservice().populateAuthorList());
        ViewAuthor_booksByAuthorList.setModel(null);
        
    }//GEN-LAST:event_ViewAuthor_DeleteAuthorButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList ViewAuthor_AuthorList;
    private javax.swing.JLabel ViewAuthor_AuthorNameLabel;
    private javax.swing.JButton ViewAuthor_DeleteAuthorButton;
    private javax.swing.JList ViewAuthor_booksByAuthorList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

}
